package com.sxj.corejava.code07_面向对象.继承;

/**
 * @author 石小俊
 * @date 2025年01月07日
 */
public class Pet {

    String name;
    int age;

    public void show() {
        System.out.println("这是父类方法");
    }

//    public Pet(){
//
//    }

//    public Pet(String name){
//        this.name = name;
//    }

    public Pet(String name, int age) {
        this.name = name;
        this.age = age;
    }

}

class Dog extends Pet {

//    public Dog(String name){
//        super(name);
//    }

    public Dog(String name, int age) {
        super(name, age);
    }

//    public Dog(){
//        super();
//    }
}

class Cat extends Pet {

    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
//    public Cat() {
//        super();
//    }

//    public Cat(String name){
//        super(name);
//    }

    public Cat(String name, int age) {
        super(name, age);
    }

    public void test() {
        // 当父类与子类中存在同名的属性时,默认访问的是子类的
        System.out.println(name);
        System.out.println(super.name);
        System.out.println(age);
        show();
        super.show();
    }

    public void show() {
        System.out.println("这是子类方法");
    }
}

class TestPet {
    public static void main(String[] args) {
        Cat cat = new Cat("宠物猫", 5);
        cat.setName("tom");
        cat.test();
    }
}

